using System;
using System.Collections.Generic;
using System.Linq;
using DataStore.Domain;
using NHibernate;
using NHibernate.Linq;

namespace DataStore.Repositories
{
    public class LanguageRepository : IRepository<Language>
    {
        readonly UnitOfWork _unitOfWork;

        public LanguageRepository(UnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
        }

        public Language Get(object id)
        {
            throw new NotImplementedException();
        }

        public void Delete(Language entity)
        {
            ISession session = _unitOfWork.Session;
            session.Delete(entity);
        }

        public void DeleteAll()
        {
            throw new NotImplementedException();
        }

        public void Save(Language entity)
        {
            ISession session = _unitOfWork.Session;
            session.Save(entity);
        }

        public Language SaveOrUpdate(Language entity)
        {
            ISession session = _unitOfWork.Session;
            session.SaveOrUpdate(entity);
            return entity;
        }

        public void Update(Language language)
        {
            ISession session = _unitOfWork.Session;
            session.Update(language);
            
        }

        IEnumerable<Language> IRepository<Language>.All
        {
            get 
            {
                ISession session = _unitOfWork.Session;
                return (from language in session.Linq<Language>()
                        orderby language.Name
                        select language).ToList();
            }
        }

        public bool Exists(Language entity)
        {
            throw new NotImplementedException();
        }

        public bool IsEmpty
        {
            get { throw new NotImplementedException(); }
        }

        public int Count(Language entity)
        {
            throw new NotImplementedException();
        }

        public int CountAll()
        {
            throw new NotImplementedException();
        }

    }
}